import 'package:dio/dio.dart';

class ProductAPI {
  final Dio _dio;

  ProductAPI(this._dio);

  // 获取商品列表
  Future<dynamic> list({int page = 1, int limit = 100}) async {
    Response res = await _dio
        .get('/products', queryParameters: {'page': page, 'limit': limit});

    return res.data;
  }

  // 获取搜索列表
  Future<dynamic> getSearchList(
      {int page = 1, int limit = 10, String keyword = ""}) async {
    Response res = await _dio.get('/products',
        queryParameters: {'page': page, 'limit': limit, 'keyword': keyword});

    return res.data;
  }

  // 获取分类列表
  Future<dynamic> getListByCategory(
      {required String sid,
      int page = 1,
      int limit = 10,
      int news = 0,
      String priceOrder = '',
      String salesOrder = ''}) async {
    Response res = await _dio.get('/products', queryParameters: {
      'page': page,
      'limit': limit,
      'sid': sid,
      'priceOrder': priceOrder,
      'salesOrder': salesOrder,
      'news': news
    });

    return res.data;
  }

  // 获取商品详情
  Future<dynamic> detail({required String id}) async {
    Response res = await _dio.get('/product/detail/' + id);
    // print('商品详情接口');
    return res.data;
  }

  // 查看当前商品的所有评论
  // 评论类型： 0=全部 1=好评 2=中评 3=差评
  Future<dynamic> comment(
      {required String id, int page = 1, int limit = 10, int type = 0}) async {
    var q = {'type': type, 'page': page, 'limit': limit};
    Response res = await _dio.get('/reply/list/' + id, queryParameters: q);

    return res.data;
  }
}
